package Day08_16;

import java.util.ArrayList;
import java.util.List;

public class Test_Collection01 {
    public static void main(String[] args) {
        Car c1 = new Car("520");
        Car c2 = new Car("1314");
        List li = new ArrayList();
        li.add(c1);
        li.add(c2);
        System.out.println( li.contains(new Car("520")) );
        li.remove(new Car("1314"));
        System.out.println(li.size());
    }
}

class Car{
    private String name;

    public Car(String name) {
        this.name = name;
    }

    public Car() {
    }

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Car car = (Car) o;
//        return Objects.equals(name, car.name);
//    }
    public boolean equals(Object o){
        if(o==null || !(o instanceof Car)){
            return false;
        }
        if(o==this){
            return true;
        }
        return this.name == ((Car) o).name;
    }
}
